package com.example.day2101;

import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;

/**
 * @author Lenovo
 */
public class SeverDemo {
    public static void main(String[] args) throws IOException {
        ServerSocket ss = new ServerSocket(10000);
        Socket s = ss.accept();
        InputStream is = s.getInputStream();
        byte[] bys = new byte[1024];
        int len = is.read(bys);
        String data = new String(bys,0,len);
        System.out.println(data);
        OutputStream os = s.getOutputStream();
        os.write("欢迎光临".getBytes());
        ss.close();
    }
}
class ClientDemo{
    public static void main(String[] args) throws IOException {
        Socket s = new Socket("127.0.0.1",10000);
        OutputStream os = s.getOutputStream();
        os.write("你好".getBytes());
        InputStream is = s.getInputStream();
        byte[] bys = new byte[1024];
        int len = is.read(bys);
        String data = new String(bys,0,len);
        System.out.println("客户端");
        s.close();
    }
}
